package yz;

/**
 * [206. 反转链表](https://leetcode-cn.com/problems/reverse-linked-list/)
 *
 * @author Yz
 * @since 2022-10-10 19:11
 */
public class LeetCode206_reverseLinkedList {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        return prev;
    }
    
    static class ListNode {
        int val;
        ListNode next;
        
        public ListNode() {
        }
        
        public ListNode(int val) {
            this.val = val;
        }
        
        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
